from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView

urlpatterns = [
    path('admin/', admin.site.urls),
    
    # API URLs
    path('api/core/', include('apps.core.urls', namespace='api_core')),
    path('api/excel/', include('apps.excel_processor.urls')),
    path('api/file-manager/', include('apps.file_manager.urls', namespace='api_file_manager')),
    path('api/analytics/', include('apps.analytics.urls', namespace='api_analytics')),
    path('api/dashboard/', include('apps.dashboard.urls', namespace='api_dashboard')),
    path('api/template-management/', include('apps.template_management.urls', namespace='api_template_management')),
    path('api/data-processing/', include('apps.data_processing.urls', namespace='api_data_processing')),
    path('api/log-analysis/', include('apps.log_analysis.urls', namespace='api_log_analysis')),
    
    # API Documentation
    path('api/schema/', SpectacularAPIView.as_view(), name='schema'),
    path('api/docs/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),
    
    # Authentication URLs，默认使用django的认证系统
    path('accounts/', include('django.contrib.auth.urls')),
    
    # Frontend URLs
    path('', include('apps.core.urls')),
    path('analytics/', include('apps.analytics.urls')),
    path('file-manager/', include('apps.file_manager.urls')),
    path('dashboard/', include('apps.dashboard.urls')),
    path('template-management/', include('apps.template_management.urls')),
    path('data-processing/', include('apps.data_processing.urls')),
    path('log-analysis/', include('apps.log_analysis.urls')),
]

# Serve media files in development
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    
    # Debug toolbar
    import debug_toolbar
    urlpatterns = [
        path('__debug__/', include(debug_toolbar.urls)),
    ] + urlpatterns